//package com.allwees.data.dataport.module.useraction.api;
//
//import java.io.IOException;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import com.allwees.bs.core.modelbase.vo.R;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.stereotype.Controller;
//
//import com.allwees.data.dataport.common.api.BaseApi;
//import com.allwees.data.dataport.module.useraction.constant.EEdmActionType;
//import com.allwees.data.dataport.module.useraction.entity.EdmLog;
//import com.allwees.data.dataport.module.useraction.req.EdmLogReq;
//import com.allwees.data.dataport.module.useraction.service.EdmLogService;
//import com.allwees.data.dataport.module.useraction.util.EdmEncryptor;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//
//@Controller
//@RequestMapping("/api/v1/pe")
//@SuppressWarnings("rawtypes")
//public class EdmLogApi extends BaseApi {
//    @Autowired
//    private EdmLogService edmLogService;
//
//    @GetMapping("/v")
//    public ResponseEntity logEdm(HttpServletRequest request, EdmLogReq req) {
//        save(req, request);
//        return new ResponseEntity(HttpStatus.OK);
//    }
//
//    /**
//     * 重定向
//     * @param k
//     * @param req
//     * @param request
//     * @param response
//     * @throws IOException
//     */
//	@GetMapping("/t")
//	public void redirect(@RequestParam(value = "k", required = false) String k, EdmLogReq req, HttpServletRequest request,
//                         HttpServletResponse response) throws IOException {
//		save(req, request);
//		response.sendRedirect(EdmEncryptor.decrypt(k));
//	}
//
//    /**
//     * 模拟图片URL，用于Email打开埋点
//     *
//     * @param request
//     * @return
//     */
//    @GetMapping("/v/{templateId}-{email}/{batchNo}/1.png")
//    public ResponseEntity buryOpen(HttpServletRequest request,
//    		@PathVariable("templateId") String templateId,
//    		@PathVariable("batchNo") String batchNo,
//    		@PathVariable("email") String email) {
//    	EdmLogReq req = new EdmLogReq()
//    			.setUaType(EEdmActionType.OPEN)
//    			.setTemplateId(templateId)
//    			.setBatchNo(batchNo)
//    			.setEmail(email);
//    	return logEdm(request, req);
//    }
//
//    @RequestMapping("/r")
//    public R refresh(int total) {
//        edmLogService.refresh(total);
//        return R.ok();
//    }
//
//    private void save(EdmLogReq req, HttpServletRequest request) {
//        EdmLog edmLog = req.toEdmLog();
//        edmLog.updateRequestInfo(request);
//        edmLogService.saveToEs(edmLog);
//    }
//}
